/*
 * Qinlan Shen
 * November 8, 2010
 * Pd. 8
 * 
 * A class representing the player character.  The Character is able to move in eight
 * directions and die when hit.  Each Character also holds values for graze and score.
 *  
 */

import java.awt.*;

public class Character extends Movable
{
	//private Player player;
	private int packetHit;
	private double speed;
	private double focusSpeed;
	private int width;
	private int height;
	private boolean active;
	private int graze;
	private int scriptBonuses;
	private int itemBonuses;
	private int lives;
	private boolean invincibility;
	
	public Character (Image i, int h, int w, int hei)
	//public Character(Player p, Image i)
	{
		hitbox = h;
		//player = p;
		x = 320;
		y = 730;
		width = w;
		height = hei;
		xSpeed = 0;
		ySpeed = 0;
		packetHit = 2;
		speed = 5;
		focusSpeed = 3;
		img = i;
		active = true;
		graze = 0;
		scriptBonuses = 0;
		itemBonuses = 0;
		lives = 3;
		invincibility = false;
	}
	
	public int getPacketHit()
	{
		return packetHit;
	}
	
	public double getSpeed()
	{
		return speed;
	}
	
	public double getFocusSpeed()
	{
		return focusSpeed;
	}
	
	public int getScore()
	{
		return graze * 10 + scriptBonuses + itemBonuses;
	}
	
	public int getGraze()
	{
		return graze;
	}
	
	public int getScriptBonuses()
	{
		return scriptBonuses;
	}
	
	public int getItemBonuses()
	{
		return itemBonuses;
	}
	
	//Checks if the Character is still alive
	public boolean getActivity()
	{
		return active;
	}
	
	//Point bonuses for surviving a script
	public void scriptBonuses(int n)
	{
		scriptBonuses += n * 50;
	}
	
	//Point bonuses from PointItems
	public void addPointItem(PointItem p)
	{
		itemBonuses += p.getValue();
	}
	
	//Disables the Character from moving
	public void kill()
	{
		if (lives <= 0)
			active = false;
		else
		{	
			lives--;
			setX(320);
			setY(730);
			invincibility = true;
		}

	}
	
	//Updates position for the Player (cannot move offscreen)
	public void update()
	{
		if (x + xSpeed - width/2 >= 0 && x + xSpeed + width <= 660)
			x += xSpeed;
		if (y + ySpeed - height/2 >= 0 && y + ySpeed + height <= 830)
			y += ySpeed;
	}
	
	//Increments graze and score due to graze
	public void incrementGraze()
	{
		graze++;
	}
	
	public boolean getInvincibility()
	{
		return invincibility;
	}
	
	public int getLives()
	{
		return lives;
	}
	
	public void setInvincibility(boolean i)
	{
		invincibility = false;
	}

}